using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor.UI;
using UnityEngine;

public class InfiniteMap : AbstractMap
{
    private Dictionary<Vector3Int, Slot> slots;

    public readonly int Height;

    public Vector3Int rangeLimitCenter;
    public int RangeLimit = 80;

    public InfiniteMap(int height) : base()
    {
        this.Height = height;
        this.slots = new Dictionary<Vector3Int, Slot>();
    }

    public bool IsOutsideOfRangeLimit(Vector3Int position)
    {
        return (position - this.rangeLimitCenter).magnitude > this.RangeLimit;
    }

    public override Slot GetSlot(Vector3Int position)
    {
        if (position.y >= this.Height || position.y < 0)
        {
            return null;
        }

        if (slots.ContainsKey(position))
        {
            return this.slots[position];
        }

        if (IsOutsideOfRangeLimit(position))
        {
            return null;
        }

        var slot = new Slot(position, this);
        slots.Add(position, slot);
        return slot;
    }

    public override IEnumerable<Slot> GetAllSlots()
    {
        return this.slots.Values;
    }
}
